<?php
/**
 * Formatter test cases.
 *
 * @internal
 * Copyright (c) 2009, Jacob Santos
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *  * Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *  * Neither the name of the DragonU nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * @author Jacob Santos <wordpress@santosj.name>
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD license
 * @package CorePress
 * @subpackage Testing
 */

/** Include PHPUnit Framework */
require_once 'PHPUnit/Framework.php';
/** Include PHPUnit Framework Testcase */
require_once 'PHPUnit/Framework/TestCase.php';

/** CorePress Formatter API */
require_once realpath(__DIR__.'/../../library/formatting.php');

/**
 * Test Suite for Formatter class.
 *
 * @package CorePress
 * @subpackage Testing
 */
class Formatter_Test extends PHPUnit_Framework_TestCase
{
	/**
	 * @ignore
	 */
	protected function setUp()
	{
		if( ! class_exists( '\CorePress\Formatter' ) )
			$this->fail('CorePress\\Formatter Class does not exist.');
	}

	/**
	 * Make sure that the constructor can be accessed.
	 *
	 * @covers CorePress\Formatter::__construct
	 */
	public function testThatContructorCanBeAccessed()
	{
		$method = new ReflectionMethod('\CorePress\Formatter', '__construct');
		$this->assertTrue( $method->isPublic() );

		$obj = new \CorePress\Formatter();
		$this->assertThat($obj, $this->isInstanceOf('\CorePress\Formatter'));
	}

	/**
	 * @depends testThatContructorCanBeAccessed
	 */
	public function testFormatterHasConstants()
	{
		$reflection = new ReflectionClass('\CorePress\Formatter');

		$this->assertTrue( $reflection->hasConstant('OBJECT'), 'Does not have OBJECT constant.' );
		$this->assertTrue( $reflection->hasConstant('OBJECT_K'), 'Does not have OBJECT_K constant.' );
		$this->assertTrue( $reflection->hasConstant('ARRAY_N'), 'Does not have ARRAY_N constant.' );
		$this->assertTrue( $reflection->hasConstant('ARRAY_A'), 'Does not have ARRAY_A constant.' );
	}

	public function testFormatterHasToMethod()
	{
		$obj = new \CorePress\Formatter();

		$this->assertTrue( method_exists($obj, 'to') );
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsArrayAToObject()
	{
		$test = array('test' => 1, 'something' => 'else');

		$expected = new stdClass();
		$expected->test = 1;
		$expected->something = 'else';

		$obj = new \CorePress\Formatter($test);

		$actual = $obj->to(\CorePress\Formatter::OBJECT);

		$this->assertSame($expected, $actual);
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsArrayAToArrayN()
	{
		$test = array('test' => 1, 'something' => 'else');

		$expected = array(1, 'else');

		$obj = new \CorePress\Formatter($test);

		$actual = $obj->to(\CorePress\Formatter::ARRAY_N);

		$this->assertSame($expected, $actual);
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsArrayAToArrayA()
	{
		$expected = array('test' => 1, 'something' => 'else');

		$obj = new \CorePress\Formatter($expected);

		$actual = $obj->to(\CorePress\Formatter::ARRAY_A);

		$this->assertSame($expected, $actual);
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsMultiArrayAToArrayA()
	{
		$expected = array();
		$expected[] = array('test' => 1, 'something' => 'else');
		$expected[] = array('test' => 2, 'something' => 'else2');

		$obj = new \CorePress\Formatter($expected);

		$actual = $obj->to(\CorePress\Formatter::ARRAY_A);

		$this->assertSame($expected, $actual);
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsMultiArrayAToArrayN()
	{
		$test = array();
		$test[] = array('test' => 1, 'something' => 'else');
		$test[] = array('test' => 2, 'something' => 'else2');

		$expected = array();
		$expected[] = array(1, 'else');
		$expected[] = array(2, 'else2');

		$obj = new \CorePress\Formatter($test);

		$actual = $obj->to(\CorePress\Formatter::ARRAY_N);

		$this->assertSame($expected, $actual);
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsArrayNToArrayA()
	{
		$test = array();
		$test[] = array(1, 'else');
		$test[] = array(2, 'else2');

		$expected = array();
		$expected[] = array(1, 'else');
		$expected[] = array(2, 'else2');

		$obj = new \CorePress\Formatter($test);

		$actual = $obj->to(\CorePress\Formatter::ARRAY_A);

		$this->assertSame($expected, $actual);
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsArrayNToArrayN()
	{
		$expected = array();
		$expected[] = array(1, 'else');
		$expected[] = array(2, 'else2');

		$obj = new \CorePress\Formatter($expected);

		$actual = $obj->to(\CorePress\Formatter::ARRAY_N);

		$this->assertSame($expected, $actual);
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsObjectToArrayN()
	{
		$test = new stdClass();
		$test->test = 1;
		$test->something = 'else';

		$expected = array(1, 'else');

		$obj = new \CorePress\Formatter($test);

		$actual = $obj->to(\CorePress\Formatter::ARRAY_N);

		$this->assertSame($expected, $actual);
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsObjectToArrayA()
	{
		$test = new stdClass();
		$test->test = 1;
		$test->something = 'else';

		$expected = array('test' => 1, 'something' => 'else');

		$obj = new \CorePress\Formatter($test);

		$actual = $obj->to(\CorePress\Formatter::ARRAY_A);

		$this->assertSame($expected, $actual);
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsObjectToObject()
	{
		$test = new stdClass();
		$test->test = 1;
		$test->something = 'else';

		$obj = new \CorePress\Formatter($test);

		$actual = $obj->to(\CorePress\Formatter::OBJECT);

		$this->assertSame($test, $actual);
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsMultiObjectToArrayN()
	{
		$this->markTestIncomplete();
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsMultiObjectToArrayA()
	{
		$this->markTestIncomplete();
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsMultiObjectToObject()
	{
		$this->markTestIncomplete();
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsPdoToArrayN()
	{
		$this->markTestIncomplete();
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsPdoToArrayA()
	{
		$this->markTestIncomplete();
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsPdoToObject()
	{
		$this->markTestIncomplete();
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsPdoToObjectK()
	{
		$this->markTestIncomplete();
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsMultiArrayArrayToObjectK()
	{
		$this->markTestIncomplete();
	}

	/**
	 * @depends testFormatterHasToMethod
	 */
	public function testFormatterConvertsMultiArrayObjectToObjectK()
	{
		$this->markTestIncomplete();
	}

}

